package com.sxj.corejava.code15_反射;

import java.lang.reflect.Modifier;
import java.util.Arrays;

/**
 * @author 石小俊
 */
public class Test02_常用方法 {
    public static void main(String[] args) {
        Class c = User.class;

        // 获取包名.类名
        System.out.println("类全名:" + c.getName());
        System.out.println("类名:" + c.getSimpleName());

        System.out.println("User类实现的接口列表:" + Arrays.toString(c.getInterfaces()));
        System.out.println("获取父类:" + c.getSuperclass());
        System.out.println("获取包名:" + c.getPackage());
        System.out.println("获取包名:" + c.getPackage().getName());
        System.out.println("User类是否是接口:" + c.isInterface());
        System.out.println("访问修饰符:" + c.getModifiers());
        if (c.getModifiers() == Modifier.PUBLIC) {
            System.out.println("当前类的修饰符为:public");
        }

        try {
            Object obj = c.newInstance();
            System.out.println(obj);
        } catch (InstantiationException e) {
            System.out.println("实例化异常,该类没有无参构造方法");
        } catch (IllegalAccessException e) {
            System.out.println("非法访问异常,该类的无参构造方法不能被外部访问");
        }

    }
}
